<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.sdry.model.llm.User"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css">
    <title>设备维修申请登记</title>
    <style type="text/css">
        .left-label {
            width: 100px !important
        }
        .icon-style {
            line-height: 39px !important
        }
    </style>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/ztree/css/zTreeStyle/zTreeStyle.css">

    <script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.all.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.exedit.js"></script>

    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">新增</i></button>
            <button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
            <%--<button class="layui-btn layui-btn-blue" lay-event="approval"><i class="layui-icon layui-icon-release">发起审批</i></button>--%>
        </div>
    </script>

    <script type="text/html" id="rowToolbar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" id="repairFinish" lay-event="repairFinish">维修完成</a>
    </script>

    <%
        User people = (User) request.getSession().getAttribute("currentUser");
        String name = null;
        if(people != null){
            name = people.getUserName();
        }
    %>
</head>
<body class="layui-view-body">


<input type="hidden" id="preRowId" name="preRowId">
<div id="dv01" class="demoTable" style="padding:10px 0 0 15px">
    <div id="dv02" class="layui-inline">
        <%--
        	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入时间检索" style="display: inline; width: 45%">
        --%>
        <input class="layui-input" name="keyword" id="keyword" placeholder="请输入设备名称"  style="display: inline; width: 100%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<div id="editDivID" hidden="hidden">
    <form class="layui-form" id="editFormID">
        <table>
            <tr>
                <td>
                    <input type="hidden" id="id" name="id">
                </td>
            </tr>
            <tr>
                <td><label class="layui-form-label left-label" style="margin-top: 20px">设备编号</label></td>
                <td>
                    <div style="width: 170px">
                        <div style="width: 150px; margin-left: 0px; float: left; margin-top: 20px">
                            <select disabled class="layui-select" id="deviceNo1" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <div style="margin-top: 29px; float: left">
                            <font style="color:red; font-size: 24px; margin-left: 4px">*</font>
                        </div>
                    </div>
                </td>
                <td><label class="layui-form-label left-label" style="margin-top: 20px;">故障设备名称</label></td>
                <td><input disabled type="text" id="deviceName1" name="deviceName" lay-verify="deviceName"  class="layui-input" style="width:150px; margin-top: 20px; display: inline;">
                    <div class="layui-inline" style="margin-top: 5px;">
                        <font style="color:red; font-size: 24px; margin-left: 4px">*</font>
                    </div>
                </td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">报修部门/车间</label></td>
                <td>
                    <div style="width: 170px">
                        <div style="width: 150px; margin-left: 0px; float: left">
                            <select disabled class="layui-select" id="repairDept1" name="repairDept" lay-verify="repairDept">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <div style="margin-top: 9px; float: left">
                            <font style="color:red; font-size: 24px; margin-left: 4px">*</font>
                        </div>
                    </div>
                </td>
                <td><label class="layui-form-label left-label">报修人</label></td>
                <td><input disabled type="text" name="repairMan" id="repairMan1" value="<%= name%>"  class="layui-input" style="width:150px"></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">报修时间</label></td>
                <td><input disabled type="text" name="repairTime" id="repairTime1"  class="layui-input" style="width:150px"></td>
                <td></td>
                <td></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">故障现象描述</label></td>
                <td colspan="3"><textarea disabled class="layui-textarea" id="errorDescribe1" name="errorDescribe" style="width: 450px; height: 100px;"></textarea></td>
            </tr>
            <%--以下6个为新新增内容--%>
            <tr style="height:10px">
                <td colspan="4">
                    <hr class="layui-bg-green" style="width: 90%; margin-left: 30px">
                </td>
            </tr>
            <tr>
                <td><label class="layui-form-label left-label">维修起始时间</label></td>
                <td><input type="text" name="fixStartTime" id="fixStartTime1"  class="layui-input" style="width:150px"></td>
                <td><label class="layui-form-label left-label">维修结束时间</label></td>
                <td><input type="text" name="fixEndTime" id="fixEndTime1"  class="layui-input" style="width:150px;"></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">维修参与人员</label></td>
                <td><input type="text" name="joinRepairMan" id="joinRepairMan1" class="layui-input" style="width:150px;"></td>
                <td><label class="layui-form-label left-label">验收日期</label></td>
                <td><input type="text" name="acceptTime" id="acceptTime1"  class="layui-input" style="width:150px;"></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">设备使用人验收</label></td>
                <td>
                    <div class="layui-input-block" style="width: 150px; margin-left: 0px">
                        <select class="layui-select" id="userAcceptance1" name="userAcceptance">
                            <option value="正常使用">正常使用</option>
                            <option value="非正常使用">非正常使用</option>
                        </select>
                    </div>
                </td>
                <td><label class="layui-form-label left-label">验收人签字</label></td>
                <td><input type="text" name="acceptManSignature" id="acceptManSignature1"  class="layui-input" style="width:150px"></td>
            </tr>
            <tr style="height:10px"></tr>
            <%--合并--%>
            <tr>
                <td colspan="4">
                    <table id="myTable">
                        <thead>
                        <tr align="center">
                            <td><label class="layui-form-label left-label" style="margin-left: 15px">更换备件名称</label></td>
                            <td><label class="layui-form-label left-label">型号规格</label></td>
                            <td><label class="layui-form-label left-label" style="margin-left: -15px">数量</label></td>
                            <td><label class="layui-form-label left-label" style="margin-left: -21px">单位</label></td>
                            <td><label class="layui-form-label left-label" style="margin-left: -86px">操作</label></td>
                        </tr>
                        </thead>
                        <tbody id="tbody">
                        <%--<c:forEach var="detail" items="${detailList}" varStatus="status">--%>
                            <tr id="tr1" align="center" style="height: 50px">
                                <td><input class="layui-input" id="changeDeviceName1" name="changeDeviceName" type="text" style="width:122px; margin-left: 27px;"></td>
                                <td><input class="layui-input" id="deviceVersion1" name="deviceVersion" type="text" style="width:122px; margin-left: 27px;"></td>
                                <td><input class="layui-input" id="deviceCount1" name="deviceCount" type="text" style="width:122px; margin-left: 27px;"></td>
                                <td><input class="layui-input" id="deviceUnit1" name="deviceUnit" type="text" style="width:122px; margin-left: 27px;"></td>
                                <td style="vertical-align: middle;"><i class="layui-icon layui-icon-add-1" id="add" style="font-size: 15px; color: #1E9FFF;"></i><%--<br><i class="layui-icon layui-icon-close" id="recover" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i>--%></td>
                            </tr>
                        <%--</c:forEach>--%>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">故障原因分析</label></td>
                <td colspan="3"><textarea class="layui-textarea" id="errorAnalysis1" name="errorAnalysis" style="width: 450px; height: 100px;"></textarea></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">处理措施</label></td>
                <td colspan="3"><textarea class="layui-textarea" id="repairHandle1" name="repairHandle" style="width: 450px; height: 100px;"></textarea></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr>
                <td><label class="layui-form-label left-label">维修结果</label></td>
                <td colspan="3"><textarea class="layui-textarea" id="repairResult1" name="repairResult" style="width: 450px; height: 100px; margin-top: 10px; margin-bottom: 15px"></textarea></td>
            </tr>
            <tr style="height:10px"></tr>
            <tr align="center">
                <td colspan="2"><button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm" style="margin-left:160px; margin-bottom: 20px">提交</button>&emsp;&emsp;&emsp;&emsp;
                <td colspan="2"><button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>
            <tr>
        </table>
    </form>
</div>

<script type="text/javascript">
    //点击"+"和"-"效果
    $(function(){
        var index;
        /* $("#add").click(function(){ */
        $("body").on("click", "#add", function() {
            //console.log($(this).parents('tr').get(0));
            var rowId = $(this).parents('tr').attr("id");
            //alert(rowId);
            var tbody = document.getElementById("tbody");
            index = tbody.rows.length + 1;
            var tab = document.getElementById('myTable');
            //指定行号
            var rowNumNext = document.getElementById(rowId).rowIndex + 1;
            //在指定行下插入一行
            var tr = tab.insertRow(rowNumNext);
            //给tr设置动态Id和样式
            tr.id = "tr" + index;
            tr.style = "text-align: center; height: 50px";
            //在行下插入列内容
            var cell0 = tr.insertCell(0);
            var cell1 = tr.insertCell(1);
            var cell2 = tr.insertCell(2);
            var cell3 = tr.insertCell(3);
            var cell4 = tr.insertCell(4);

            cell0.innerHTML = '<td><input class="layui-input" id="changeDeviceName" name="changeDeviceName" type="text" style="width:122px; margin-left: 27px;"></td>';
            cell1.innerHTML = '<td><input class="layui-input" id="deviceVersion" name="deviceVersion" type="text" style="width:122px; margin-left: 27px;"></td>';
            cell2.innerHTML = '<td><input class="layui-input" id="deviceCount" name="deviceCount" type="text" style="width:122px; margin-left: 27px;"></td>';
            cell3.innerHTML = '<td><input class="layui-input" id="deviceUnit" name="deviceUnit" type="text" style="width:122px; margin-left: 27px;"></td>';
            cell4.innerHTML = '<td><i class="layui-icon layui-icon-add-1" id="add" style="font-size: 15px; color: #1E9FFF;"></i><br><i class="layui-icon layui-icon-close" id="recover" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i></td>';
        });

        $("body").on("click", "#recover", function() {
            var rowId = $(this).parents('tr').attr("id");
            $("#"+rowId).remove();
        })
    });
    layui.use(['table','layer','upload','form','laydate'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;

        var $ = layui.jquery, active = {
            reload:function () {
                //var searchTime = $("#searchTime").val();
                var keyword01 = $("#keyword").val();
                //console.log(searchTime + ',' + keyword);
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01},
                    page: {
                        curr: 1
                    }
                });
            }
        }
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/breakdown/queryDeviceBreakdown.do'
            ,toolbar: '#toolbar'
            ,title: '设备故障维修单'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,cols: [[
                {type: 'checkbox', fixed: 'left', },
                {field:'', title:'序号', sort: true, type:'numbers', width: 60},
                {field:'deviceName', title:'故障设备名称'},
                {field:'deviceNo', title:'设备编号'},
                {field:'repairDept', title:'报修部门/车间'},
                {field:'repairMan', title:'报修人'},
                {field:'repairTime', title:'报修时间'},
                {field:'errorDescribe', title:'故障现象描述'},
                {field:'joinRepairMan', title:'维修参与人员'},
                {field:'fixStartTime', title:'维修起始时间'},
                {field:'fixEndTime', title:'维修结束时间'},
                /*{field:'fixMan', title:'维修人'},*/
                {field:'userAcceptance', title:'设备使用人验收'},
                {field:'acceptTime', title:'验收日期'},
                {field:'acceptManSignature', title:'验收人签字'},
                {field:'errorAnalysis', title:'故障原因分析'},
                {field:'repairHandle', title:'处理措施'},
                {field:'repairResult', title:'维修结果'},
                /*新添加字段*/
                {field:'approvalPeople', title:'审批人'},
                {field:'approvalStatus', title:'审批状态', templet: function(row){
                    if(row.approvalStatus == '0'){
                        return '审批中';
                    } else if (row.approvalStatus == '1') {
                        return '审批通过';
                    } else {
                        return '已驳回';
                    }
                }},
                {field:'approvalTime', title:'审批时间', templet: function(row){
                    if(row.approvalTime == ''){
                        return '';
                    } else {
                        return createTime(row.approvalTime);
                    }
                }},
                {field:'approvalOpinion', title:'审批意见'},
                ,{field:'op1', title:'更换详细', templet:function (rowData){
                        return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='deviceMaintenanceRecordDetailEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#rowToolbar', width: 220}
            ]],
            page: true
        });

        //头工具栏事件
        table.on('toolbar(tableList)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                //新增
                case 'add':
                    layer.open({
                        type: 1 					//Page层类型
                        ,area: ['720px', '470px'] 	//宽  高
                        ,title: '新增'
                        ,shade: 0.6 				//遮罩透明度
                        ,maxmin: true 				//允许全屏最小化
                        ,anim: 1 					//0-6的动画形式，-1不开启
                        //,content: $("#addFormID")
                        ,content: '<form class="layui-form" id="addFormID">'+
                            '<table>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label" style="margin-top: 20px">设备编号</label></td>'+
                                    '<td>'+
                                        '<div>'+
                                            '<div style="width: 200px; margin-left: 0px; float: left; margin-top: 20px">'+
                                                '<select class="layui-select" id="deviceNo" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">'+
                                                    '<option value="">请选择</option>'+
                                                '</select>'+
                                            '</div>'+
                                            '<div style="margin-top: 29px; float: left">'+
                                                '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                            '</div>'+
                                        '</div>'+
                                    '</td>'+
                                    '<td><label class="layui-form-label left-label" style="margin-top: 20px;">故障设备名称</label></td>'+
                                    '<td><input type="text" id="deviceName" name="deviceName" lay-verify="deviceName" class="layui-input" style="width:200px; margin-top: 20px; display: inline;">' +
                                        '<div class="layui-inline" style="margin-top: 4px;">'+
                                            '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                        '</div>'+
                                    '</td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">报修部门/车间</label></td>'+
                                    '<td>'+
                                        '<div>'+
                                            '<div style="width: 200px; margin-left: 0px; float: left">'+
                                                '<select class="layui-select" id="repairDept" name="repairDept" lay-verify="repairDept">'+
                                                    '<option value="">请选择</option>'+
                                                '</select>'+
                                            '</div>'+
                                            '<div style="margin-top: 9px; float: left">'+
                                                '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                            '</div>'+
                                        '</div>'+
                                    '</td>'+
                                    '<td><label class="layui-form-label left-label">报修人</label></td>'+
                                    '<td><input type="text" name="repairMan" id="repairMan" value="<%= name%>" class="layui-input" style="width:200px"></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">报修时间</label></td>'+
                                    '<td><input type="text" name="repairTime" id="repairTime"  class="layui-input" style="width:200px"></td>'+
                                    '<td></td>'+
                                    '<td></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">故障现象描述</label></td>'+
                                    '<td colspan="3"><textarea class="layui-textarea" id="errorDescribe" name="errorDescribe" style="width: 540px; height: 150px;"></textarea></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td colspan="2">' +
                                        '<label class="layui-form-label">审批人</label>' +
                                        '<input readonly class="layui-input" lay-verify="approvalPeople" placeholder="请选择审批人" name="approvalPeople" id="approvalPeople" type="text" style="width:100px; display:inline; margin-left: 19px">' +
                                        '<i style="font-size:15px;" id="refresh" class="layui-icon layui-icon-refresh"></i>' +
                                        '<ul id="treeConfig" class="ztree" style="margin-left: 120px;"></ul>'+
                                    '</td>'+
                                    '<td colspan="2">' +
                                        '<label class="layui-form-label">抄送人</label>' +
                                        '<input readonly class="layui-input" lay-verify="ccPeople" placeholder="请选择三个抄送人" name ="ccPeople" id="ccPeople" type="text" style="width:200px; display:inline">' +
                                        '<i style="font-size: 15px;" id="dCopyMenRefresh" class="layui-icon layui-icon-refresh"></i>'+
                                        '<ul id="dCopyMenConfig" class="ztree" style="margin-left: 100px;"></ul>'+
                                    '</td>'+
                                '</tr>'+
                                /*'<tr style="height:10px">' +
                                    '<td colspan="4">'+
                                '<hr class="layui-bg-green" style="width: 100%">'+
                                '</td>'+
                                '</tr>'+
                                /!*以下6个为新新增内容*!/
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">维修起始时间</label></td>'+
                                    '<td><input disabled type="text" name="fixStartTime" id="fixStartTime"  class="layui-input" style="width:150px"></td>'+
                                    '<td><label class="layui-form-label left-label">维修结束时间</label></td>'+
                                    '<td><input disabled type="text" name="fixEndTime" id="fixEndTime"  class="layui-input" style="width:150px;"></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">维修参与人员</label></td>'+
                                    '<td><input disabled type="text" name="joinRepairMan" id="joinRepairMan" class="layui-input" style="width:150px;"></td>'+
                                    '<td><label class="layui-form-label left-label">验收日期</label></td>'+
                                    '<td><input disabled type="text" name="acceptTime" id="acceptTime"  class="layui-input" style="width:150px;"></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">设备使用人验收</label></td>'+
                                    '<td>'+
                                        '<div class="layui-input-block" style="width: 150px; margin-left: 0px">'+
                                            '<select disabled class="layui-select" id="userAcceptance" name="userAcceptance">'+
                                                '<option value="正常使用">正常使用</option>'+
                                                '<option value="非正常使用">非正常使用</option>'+
                                            '</select>'+
                                        '</div>'+
                                    '</td>'+
                                    '<td><label class="layui-form-label left-label">验收人签字</label></td>'+
                                    '<td><input disabled type="text" name="acceptManSignature" id="acceptManSignature"  class="layui-input" style="width:150px"></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                /!*合并*!/
                                '<tr>'+
                                    '<td colspan="4">'+
                                '<table id="myTable">'+
                                '<thead>'+
                                '<tr align="center">'+
                                    '<td><label class="layui-form-label left-label" style="margin-left: 15px">更换备件名称</label></td>'+
                                    '<td><label class="layui-form-label left-label">型号规格</label></td>'+
                                    '<td><label class="layui-form-label left-label" style="margin-left: -15px">数量</label></td>'+
                                    '<td><label class="layui-form-label left-label" style="margin-left: -21px">单位</label></td>'+
                                /!*'<td><label class="layui-form-label left-label" style="margin-left: -86px">操作</label></td>'+*!/
                                '</tr>'+
                                '</thead>'+
                                '<tbody id="tbody">'+
                                '<tr id="tr1" align="center">'+
                                    '<td><input disabled class="layui-input" id="changeDeviceName" name="changeDeviceName" type="text" style="width:122px; margin-left: 27px; margin-bottom: 15px"></td>'+
                                    '<td><input disabled class="layui-input" id="deviceVersion" name="deviceVersion" type="text" style="width:122px; margin-left: 27px; margin-bottom: 15px"></td>'+
                                    '<td><input disabled class="layui-input" id="deviceCount" name="deviceCount" type="text" style="width:122px; margin-left: 27px; margin-bottom: 15px"></td>'+
                                    '<td><input disabled class="layui-input" id="deviceUnit" name="deviceUnit" type="text" style="width:122px; margin-left: 27px; margin-bottom: 15px"></td>'+
                                /!*'<td style="vertical-align: middle;"><i class="layui-icon layui-icon-add-1" id="add" style="font-size: 15px; color: #1E9FFF;"></i><br><i class="layui-icon layui-icon-close" id="recover" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i></td>'+*!/
                                '</tr>'+
                                '</tbody>'+
                                '</table>'+
                                    '</td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">故障原因分析</label></td>'+
                                    '<td colspan="3"><textarea disabled class="layui-textarea" id="errorAnalysis" name="errorAnalysis" style="width: 450px; height: 100px;"></textarea></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">处理措施</label></td>'+
                                    '<td colspan="3"><textarea disabled class="layui-textarea" id="repairHandle" name="repairHandle" style="width: 450px; height: 100px;"></textarea></td>'+
                                '</tr>'+
                                '<tr style="height:10px"></tr>'+
                                '<tr>'+
                                    '<td><label class="layui-form-label left-label">维修结果</label></td>'+
                                    '<td colspan="3"><textarea disabled class="layui-textarea" id="repairResult" name="repairResult" style="width: 450px; height: 100px; margin-top: 10px; margin-bottom: 15px"></textarea></td>'+
                                '</tr>'+*/
                                '<tr style="height:20px"></tr>'+
                                '<tr align="center">'+
                                    '<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:160px; margin-bottom: 20px">提交</button>&emsp;&emsp;'+
                                    '<td colspan="2"><button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button>'+
                                '<tr>'+
                            '</table>'+
                        '</form>'
                        ,success: function(){
                            //报修时间
                            laydate.render({
                                elem: '#repairTime'
                            });
                            //维修起始时间
                            laydate.render({
                                elem: '#fixStartTime'
                            });
                            //维修结束时间
                            laydate.render({
                                elem: '#fixEndTime'
                            });
                            //验收日期
                            laydate.render({
                                elem: '#acceptTime'
                            });

                            //下拉查找所有设备
                            $.ajax({
                                type: 'POST',
                                url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
                                dataType: 'json',
                                async: false,
                                success: function (data){
                                    for (var i = 0; i < data.length; i++) {
                                        $("#deviceNo").append("<option value='"+ data[i].deviceNo +"'>"+ data[i].deviceNo +"</option>");
                                    }
                                }
                            });
                            //下拉框查找所有部门
                            $.ajax({
                                type: 'POST',
                                url: '${pageContext.request.contextPath}/device/queryAllDeptList.do',
                                dataType: 'json',
                                async: false,
                                success: function (data){
                                    for (var i = 0; i < data.length; i++) {
                                        $("#repairDept").append("<option value='"+ data[i].name +"'>"+ data[i].name +"</option>");
                                    }
                                }
                            });

                            $("#refresh").click(function(){
                                $("#approvalPeople").val("");
                            })
                            $("#dCopyMenRefresh").click(function(){
                                $("#ccPeople").val("");
                            })

                            var setting = {
                                isSimpleData : true,             //数据是否采用简单 Array 格式，默认false
                                treeNodeKey : "id",              //在isSimpleData格式下，当前节点id属性
                                treeNodeParentKey : "pId",       //在isSimpleData格式下，当前节点的父节点id属性
                                showLine : true,                 //是否显示节点间的连线
                                checkable : true,                //每个节点上是否显示 CheckBox
                                data: {
                                    simpleData: {
                                        enable: true,
                                        idKey: "id",
                                        pIdKey: "pId",
                                        rootPid: "0"
                                    }
                                },
                                callback: {
                                    onDblClick: onDblClick,
                                }
                            };

                            var dCopyMenSetting = {
                                isSimpleData : true,              //数据是否采用简单 Array 格式，默认false
                                treeNodeKey : "id",               //在isSimpleData格式下，当前节点id属性
                                treeNodeParentKey : "pId",        //在isSimpleData格式下，当前节点的父节点id属性
                                showLine : false,                 //是否显示节点间的连线
                                data: {
                                    simpleData: {
                                        enable: true,
                                        idKey: "id",
                                        pIdKey: "pId",
                                        rootPid: "0"
                                    }
                                },
                                callback: {
                                    onDblClick: dCopyMenOnDblClick,
                                }
                            };

                            function onDblClick(e,treeId,treeNode) {
                                selectedNode = treeNode;
                                var name = treeNode.name;
                                var id = treeNode.id;
                                var type = treeNode.type;
                                if(type != "-1"){
                                    var dApprover1 = $("#approvalPeople").val();
                                    var dApprovers = dApprover1.split(",");
                                    for(var i=0;i < dApprovers.length;i++){
                                        if(name == dApprovers[i]){
                                            toastrStyle();
                                            toastr.warning("选择了重复的审批人！")
                                            name = "";
                                        }
                                    }
                                    var dApprover2;
                                    if(dApprover1 == "" && name != ""){
                                        dApprover2 = $("#approvalPeople").val((dApprover1+','+name).substring(1));
                                    }else if(name != ""){
                                        dApprover2 = $("#approvalPeople").val(dApprover1+','+name);
                                    }
                                    var dApprover3 =  $("#approvalPeople").val();
                                    var dApprovers3 = dApprover3.split(",");
                                    var dApprovers3Length = dApprovers3.length;
                                    if(dApprovers3Length > 1){
                                        toastrStyle();
                                        toastr.warning("最多选择1个审批人");
                                        $("#approvalPeople").val(dApprover1);
                                    }
                                }else{
                                    toastrStyle();
                                    toastr.warning("请选择审批人！")
                                }
                            }

                            function dCopyMenOnDblClick(e,treeId,treeNode) {
                                dCopyMenSelectedNode = treeNode;
                                var name = treeNode.name;
                                var id = treeNode.id;
                                var type = treeNode.type;
                                if (type != "-1") {
                                    var dCopyMen1 = $("#ccPeople").val();
                                    var dCopyMens = dCopyMen1.split(",");
                                    for (var i = 0; i < dCopyMens.length; i++) {
                                        if (name == dCopyMens[i]) {
                                            toastrStyle();
                                            toastr.warning("选择了重复的抄送人！")
                                            name = "";
                                        }
                                    }
                                    var dCopyMen2;
                                    if (dCopyMen1 == "" && name != "") {
                                        dCopyMen2 = $("#ccPeople").val((dCopyMen1 + ',' + name).substring(1));
                                    } else if (name != "") {
                                        dCopyMen2 = $("#ccPeople").val(dCopyMen1 + ',' + name);
                                    }
                                    var dCopyMen3 = $("#ccPeople").val();
                                    var dCopyMens3 = dCopyMen3.split(",");
                                    var dCopyMens3Length = dCopyMens3.length;
                                    if (dCopyMens3Length > 3) {
                                        toastrStyle();
                                        toastr.warning("最多选择3个抄送人");
                                        $("#ccPeople").val(dCopyMen1);
                                    }
                                } else {
                                    toastrStyle();
                                    toastr.warning("请选择抄送人！")
                                }
                            }
                            $.ajax({
                                type:'get',
                                url:'${pageContext.request.contextPath }/disposeRejects/getZtreeJson.do',
                                dataType:'json',
                                success: function(data){
                                    var	zNodes = data.rows;
                                    $(document).ready(function() {
                                        $.fn.zTree.init($("#treeConfig"), setting, zNodes);
                                    });
                                },
                                error: function(){
                                    toastrStyle();
                                    toastr.error("请求失败");
                                }
                            });

                            $.ajax({
                                type:'get',
                                url:'${pageContext.request.contextPath }/disposeRejects/getZtreeJson.do',
                                dataType:'json',
                                success: function(data){
                                    var	dCopyMenzNodes = data.rows;
                                    $(document).ready(function() {
                                        $.fn.zTree.init($("#dCopyMenConfig"), dCopyMenSetting, dCopyMenzNodes);
                                    });
                                },
                                error: function(){
                                    toastrStyle();
                                    toastr.error("请求失败");
                                }
                            });

                            //初始化radio、select等元素
                            form.render();
                        }
                    });
                break;
                //批量删除
                case 'delete':
                    var data = checkStatus.data;
                    var idArr = new Array();
                    if(data.length == 0){
                        toastrStyle();
                        toastr.warning("请至少选择一条记录！");
                    }
                    for(var i=0;i < data.length;i++){
                        /*alert(data[i].id)*/
                        idArr[i] = data[i].id;
                    }
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/breakdown/deleteDeviceBreakdownById.do',
                        data:{"idArr" : idArr},
                        success:function(data){
                            layer.confirm('确定删除吗？', function(index){
                                if(data > 0){
                                    toastrStyle();
                                    toastr.success("删除成功！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }else{
                                    toastrStyle();
                                    toastr.warning("删除失败！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }
                            });
                        }
                    });
                break;
                case 'approval':
                    var data = checkStatus.data;
                    var idArr = new Array();
                    if(data.length==0){
                        toastr.warning("请至少选择一条记录！");
                        return false;
                    }
                    var ids = '';
                    for(var i=0;i<data.length;i++){
                        /* if (data[i].reserve1 != '0' && data[i].reserve1 != '2' && data[i].reserve1 != '4') {
                            toastr.warning("不能重复提交审批！");
                            return false;
                        } */
                        if (i == 0) {
                            ids = ids + data[i].id;
                        } else {
                            ids = ids + ',' + data[i].id;
                        }
                    }


                    $("#ids").val(ids);
                    layer.open({
                        type: 1 		//Page层类型
                        ,area: ['30%', '70%'] //宽  高
                        ,title: '选择审批人'
                        ,shade: 0.6 	//遮罩透明度
                        ,maxmin: true //允许全屏最小化
                        ,anim: 1 		//0-6的动画形式，-1不开启
                        ,content:$("#formDiv2")
                        ,success: function(data){

                        }
                        ,end: function () {
                            var formDiv = document.getElementById('formDiv2');
                            formDiv.style.display = '';
                        }
                    });
                    break;
                case 'select':
                    /*console.log(obj)*/
                break;
            };
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var idArr = new Array();
            //单个删除
            if(obj.event === 'del'){
                var data = obj.data;
                layer.confirm('确定删除吗？', function(index){
                    var id = obj.data.id;
                    idArr[0] = id;
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/breakdown/deleteDeviceBreakdownById.do',
                        data:{ "idArr" : idArr },
                        success:function(data){
                            if(data > 0){
                                toastrStyle();
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }else{
                                toastrStyle();
                                toastr.warning("删除失败！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                $("#deviceNo1").find("option").not(":first").remove();
                $("#repairDept1").find("option").not(":first").remove();
                var data = obj.data;
                //window.location.href="${pageContext.request.contextPath }/breakdown/queryLoopById.do?id="+data.id;
                layer.open({
                    type: 1 							//Page层类型
                    ,area: ['660px', '470px']				//宽  高
                    ,title: '编辑'
                    ,shade: 0.6 						//遮罩透明度
                    ,maxmin: true 					    //允许全屏最小化
                    ,anim: 1 							//0-6的动画形式，-1不开启
                    ,content: $("#editDivID")
                    ,end: function(){
                        $("#editDivID").hide();
                    }
                    ,success: function(){
                        /* $("#deviceNo").val(data.deviceNo);
                        form.render("select","selFilter");
                        $.ajax({
                            type:'post',
                            url:'${pageContext.request.contextPath }/breakdown/queryLoopById.do',
                            data:{"id" : data.id},
                            success:function(result){
                                var obj = eval("("+result+")")
                                console.log(obj.length);
                                for (var i = 0; i < obj.length; i++) {

                                }
                                alert(result.length);
                            }
                        });*/
                        $("#id").val(data.id);
                        $("#deviceName1").val(data.deviceName);
                        $("#repairMan1").val(data.repairMan);
                        $("#repairTime1").val(data.repairTime);
                        $("#joinRepairMan1").val(data.joinRepairMan);
                        $("#fixStartTime1").val(data.fixStartTime);
                        $("#fixEndTime1").val(data.fixEndTime);
                        $("#fixMan1").val(data.fixMan);
                        $("#userAcceptance1").val(data.userAcceptance);
                        $("#acceptTime1").val(data.acceptTime);
                        $("#acceptManSignature1").val(data.acceptManSignature);
                        $("#errorDescribe1").val(data.errorDescribe);
                        $("#errorAnalysis1").val(data.errorAnalysis);
                        $("#repairHandle1").val(data.repairHandle);
                        $("#repairResult1").val(data.repairResult);
                        //下拉查找所有设备
                        $.ajax({
                            type: 'POST',
                            url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
                            dataType: 'json',
                            async: false,
                            success: function (datas){
                                for (var i = 0; i < datas.length; i++) {
                                    $("#deviceNo1").append("<option value='"+ datas[i].deviceNo +"'>"+ datas[i].deviceNo +"</option>");
                                    if(datas[i].deviceNo == data.deviceNo){
                                        $("#deviceNo1").val(data.deviceNo);
                                    }
                                }
                                form.render();
                            }
                        });
                        //下拉框查找所有部门
                        $.ajax({
                            type: 'POST',
                            url: '${pageContext.request.contextPath}/device/queryAllDeptList.do',
                            dataType: 'json',
                            async: false,
                            success: function (datas){
                                for (var i = 0; i < datas.length; i++) {
                                    $("#repairDept1").append("<option value='"+ datas[i].name +"'>"+ datas[i].name +"</option>");
                                    if(datas[i].name == data.repairDept){
                                        $("#repairDept1").val(data.repairDept);
                                    }
                                }
                                form.render();
                            }
                        });
                    }
                });
            } else if(obj.event === 'repairFinish'){
                var data = obj.data;
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath }/breakdown/confirmRepairFinish.do',
                    data:{ "id" : data.id },
                    success:function(data){
                        if(data > 0){
                            toastrStyle();
                            toastr.success("维修完成！");
                            setTimeout(function(){
                                location.reload();
                            },1000);
                        }else{
                            toastrStyle();
                            toastr.warning("维修异常！");
                            setTimeout(function(){
                                location.reload();
                            },1000);
                        }
                    }
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)(新增)
         */
        form.on('submit(addForm)', function (data) {
            $("#subBtn").attr("disabled",true);
            $.ajax({
                url : '${pageContext.request.contextPath}/breakdown/addDeviceBreakdown.do',
                data: $("#addFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        /**
         * 通用表单提交(AJAX方式)(编辑)
         */
        form.on('submit(editForm)', function (data) {
            //console.log(data.field.id);
            $.ajax({
                url : '${pageContext.request.contextPath}/breakdown/editDeviceBreakdownById.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        /*————————————*/
                        $("#tbody tr").each(function(i,dom){
                            var tr = $(dom).closest("tr");
                            var tds = tr.find("td");
                            //主表插入行ID
                            var mId = data.field.id;
                            var changeDeviceName = tds[0].getElementsByTagName("input")[0].value;
                            var deviceVersion = tds[1].getElementsByTagName("input")[0].value;
                            var deviceCount = tds[2].getElementsByTagName("input")[0].value;
                            var deviceUnit = tds[3].getElementsByTagName("input")[0].value;
                            console.log(mId + "," + changeDeviceName + "," + deviceVersion + "," + deviceCount + "," + deviceUnit);
                            $.ajax({
                                type:'post'
                                ,url:'${pageContext.request.contextPath}/breakdown/addDeviceMaintenanceRecordsDetail.do'
                                ,data:{mId: mId, changeDeviceName: changeDeviceName, deviceVersion: deviceVersion, deviceCount: deviceCount, deviceUnit: deviceUnit}
                                ,dataType:'json'
                                ,async: false
                                ,success:function(data){

                                }
                            })
                        });
                        toastrStyle();
                        toastr.success('修改成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('修改失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        /**
         * 新增表单校验
         */
        form.verify({
            //value：表单的值item：表单的DOM对象
            deviceName: function(value, item){
                if(value == ''){
                    return '设备名称不能为空';
                }
            },
            deviceNo: function(value, item){
                if(value == ''){
                    return '设备编号不能为空';
                }
            },
            repairDept: function(value, item){
                if(value == ''){
                    return '报修部门不能为空';
                }
            },
            approvalPeople: function(value, item){
                if(value == ''){
                    return '审批人不能为空';
                }
            }
        });

        //查找带回
        form.on('select(displayInfo)', function(data){
            $.ajax({
                type: 'POST',
                url: '${pageContext.request.contextPath}/device/queryDeviceInfoByNo.do',
                data: {deviceNo:$('#deviceNo').val()},
                /* dataType: 'json', */
                /* async: false, */
                success: function (data){
                    var device = eval('(' +data+ ')');
                    $('#deviceName').val(device.deviceName);
                }
            });
        });

        //报修时间
        laydate.render({
            elem: '#repairTime1'
        });
        //维修开始时间
        laydate.render({
            elem: '#fixStartTime1'
        });
        //维修结束时间
        laydate.render({
            elem: '#fixEndTime1'
        });
        //维修日期/时间
        laydate.render({
            elem: '#acceptTime1'
        });
    });

    //提示框样式
    function toastrStyle() {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

    //根据保养记录表ID查询更换设备详细
    function deviceMaintenanceRecordDetailEvent(mId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '更换设备详细'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/maintResume/queryDeviceMaintenanceRecordDetailById.do?mId='+mId
                        /*,where:{dId:thisRowId.id}*/
                        /*,toolbar: '#toolbar'*/
                        ,title: '更换设备详细'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'changeDeviceName', title:'更换设备名称'},
                            {field:'deviceVersion', title:'型号规格'},
                            {field:'deviceCount', title:'数量'},
                            {field:'deviceUnit', title:'单位'}
                        ]]
                        ,page: false
                    });
                });
            }
        });
    }

    //日期格式转换1
    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var M = date.getMonth()+1;
        M = M<10?'0'+M:M;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var m = date.getMinutes();
        m = m<10?("0"+m):m;
        var str = y+"-"+M+"-"+d+" "+h+":"+m;
        return str;
    }
</script>
</body>
</html>